#pragma once 

#include <iostream>
#include <string>
#include <unistd.h>

class Handler 
{
  public:
		Handler()
    {}
		~Handler()
   {}
    void operator()(int sock,std::string ip,int port)
    {
      char buff[1024];
      while(true)
      {
        ssize_t size=read(sock,buff,sizeof(buff));
        if(size>0)
        {
          buff[size]=0;
          std::cout<<ip<<':'<<port<<'#'<<buff<<std::endl;

          write(sock,buff,size);
        }else if(size==0)
        {
          std::cout<<ip<<":"<<port<<"退出"<<std::endl;
          break;
        }else{
          std::cerr<<ip<<':'<<port<<':'<<sock<<" read error"<<std::endl;
      break;      
        }
      }
      std::cout<<"sercive don"<<std::endl;
      close(sock);
  }
};
class Task
{
  private:
    int sock;
    std::string ip;
    int port;
    Handler handler;
  public:
    Task()
    {}
    Task(int _sock,std::string _ip,int _port)
      :sock(_sock),ip(_ip),port(_port)
    {}
    ~Task()
    {}
    void Run()
    {
      handler(sock,ip,port);
    }
};
